"""
版本号：1.0
日期：2025/4/9
描述：
"""
import configparser
import json
import os

FILE_DIR = os.path.dirname(os.path.abspath(__file__))


def initialize_config():
    """ 初始化配置文件 """
    config = configparser.ConfigParser()
    config.read(os.path.join(FILE_DIR, 'config.ini'), encoding='utf-8')
    return config


def initialize_mcp_json():
    """ 初始化 MCP JSON 配置 """

    files = os.listdir(os.path.join(FILE_DIR, 'mcp_server'))
    result_list = []
    for file in files:
        if file.endswith('.json'):
            with open(os.path.join(FILE_DIR, 'mcp_server', file), 'r', encoding='utf-8') as f:
                result_list.append(json.load(f))
    return result_list


def get_server_info(server_json):
    """ 获取mcp 服务的 command，args和 env"""

    mcp_servers = server_json.get('mcpServers', {})
    for server_type, server_config in mcp_servers.items():
        command = server_config.get('command')
        args = server_config.get('args', [])
        env = server_config.get('env', {})
        return command, args, env, server_type


if __name__ == '__main__':
    pass
